<?php
/**
 * Created by 2019/11/23 0023
 * Effect: ValidateTool.php
 * Author: 品花
 * Date: 2019/11/23 0023
 * Time: 上午 11:01
 */

namespace App\Validate;

use EasySwoole\Validate\Validate;


class ValidateTool
{

    /**
     * 参数验证规则
     * @param $action
     * @return Validate
     * @author 品花
     * @date 2019/11/23 0023 下午 2:22
     */
   public static function validateRule($action,$param){

       $Validate = new Validate();
//        var_dump($action);
       switch ($action){
           //登录
           case '/Api/V1/Login/login':{
               $Validate->addColumn('ip','ip')->required()->isIp();
//               $Validate->addColumn('mobile','手机号')->required()->length(11);
//               $Validate->addColumn('password','密码')->required()->lengthMin(6);
               $Validate->addColumn('type', '登录类型')->required()->inArray(["1","2","3"],true);
//               $Validate->addColumn('code','验证码')->lengthMin(6);
//               $Validate->addColumn('openid','微信标识')->lengthMax(64);
               break;
           }
           //注册
           case '/Api/V1/Login/register':{

               $Validate->addColumn('mobile','手机号')->required()->length(11);
               $Validate->addColumn('code','验证码')->required()->length(6);
               $Validate->addColumn('ip','ip')->required()->isIp();
//               $Validate->addColumn('password','密码')->required()->lengthMin(6);

               break;
           }
           //发送验证码
           case '/Api/V1/Login/sendCode':{
               $Validate->addColumn('mobile','手机号')->required()->length(11);
               break;
           }
           //找回密码
           case '/Api/V1/Login/resetPassword':{

               $Validate->addColumn('password','密码')->required()->lengthMin(6);
               break;
           }
           //重置手机号码
           case '/Api/V1/Login/resetMobile':{

               $Validate->addColumn('mobile','手机号')->required()->length(11);
               $Validate->addColumn('code','验证码')->required()->length(6);
               break;
           }
           //获取JSapi
           case '/Api/V1/Login/getJsapiData':{
               $Validate->addColumn('url','url链接')->required()->lengthMin(1);
               break;
           }
           //绑定微信
           case '/Api/V1/Login/bindWechat':{
               $Validate->addColumn('openid','微信openid')->required()->betweenLen(1,32);
               $Validate->addColumn('sex', 'sex')->required()->inArray(["0","1","2"],true);
               $Validate->addColumn('avatar','头像')->required();
               $Validate->addColumn('nick', '昵称')->required();
               break;
           }
           //用户编辑
           case '/Api/V1/User/edit':{
               $Validate->addColumn('type', '类型')->required()->inArray(["1","2","3"],true);
               $Validate->addColumn('value', '信息')->required()->betweenLen(1,255);
               break;
           }


           //获取版本信息
           case '/Api/V1/Version/getVersion':{
               $Validate->addColumn('version','版本号')->required()->betweenLen(5,20);
               $Validate->addColumn('device_type','设备类型')->required()->inArray(["1","2"],true);
               break;
           }

           //加车
           case '/Api/V1/Cart/create':{
               $Validate->addColumn('id','ID')->required()->integer();
               $Validate->addColumn('number','数量')->required()->integer();
               break;
           }

           //更新库存
           case '/Api/V1/Cart/update':{
               $Validate->addColumn('id','ID')->required()->integer();
               $Validate->addColumn('number','数量')->required()->integer();
               break;
           }

           //删除购物车
           case '/Api/V1/Cart/delete':{
               $Validate->addColumn('id','ID')->required()->integer();
               break;
           }

           //创建订单
           case '/Api/V1/Order/create':{
               $Validate->addColumn('ids','产品')->required()->lengthMin(1);
               $Validate->addColumn('from','来源')->required()->inArray(["1","2"],true);
               $Validate->addColumn('pay_type','支付类型')->required()->inArray(["1","2"],true);
               $Validate->addColumn('address_id','收货地址ID')->required()->integer();
               $Validate->addColumn('distribution_type','配送日')->required()->inArray(["0","1","2"],true);
               $Validate->addColumn('distribution_time','配送时段')->required()->lengthMin(2);
               break;
           }

           //获取订单
           case '/Api/V1/Order':{

               $Validate->addColumn('state','订单状态')->required()->inArray(["-2","0","1","2","3"],true);

               break;
           }
           //删除订单
           case '/Api/V1/Order/delete':{

               $Validate->addColumn('id','ID')->required()->integer();
               break;
           }
           //设置支付类型
           case '/Api/V1/Order/setOrderPayType':{

               $Validate->addColumn('order_id','订单ID')->required()->integer();
               $Validate->addColumn('pay_type','支付类型')->required()->inArray(["1","2"],true);
               break;
           }

           //获取支付数据
           case '/Api/V1/Order/getPayData':{

               $Validate->addColumn('id','订单ID')->required()->integer();
               $Validate->addColumn('device_type','设备类型')->required()->inArray(["1","2"],true);
               break;
           }

           //添加收货地址
           case '/Api/V1/Address/create':{
               $Validate->addColumn('surname','姓')->required()->lengthMin(1);
               $Validate->addColumn('name','名')->required()->lengthMin(1);
               $Validate->addColumn('phone','手机号')->required()->length(11);
               $Validate->addColumn('sex','性别')->required()->inArray(["1","2"],true);
               $Validate->addColumn('province','省')->required()->lengthMin(2);
               $Validate->addColumn('city','市')->required()->lengthMin(2);
               $Validate->addColumn('area','区')->required()->lengthMin(2);
//               $Validate->addColumn('postcode','邮编')->required()->length(6);
               $Validate->addColumn('detail','详细地址')->required()->lengthMin(4);

               $Validate->addColumn('state','状态')->required()->inArray(["0","1","2"],true);
               break;
           }

           //添加收货地址
           case '/Api/V1/Address/edit':{
               $Validate->addColumn('id','ID')->required()->integer();
               $Validate->addColumn('surname','姓')->required()->lengthMin(1);
               $Validate->addColumn('name','名')->required()->lengthMin(1);
               $Validate->addColumn('phone','手机号')->required()->length(11);
               $Validate->addColumn('sex','性别')->required()->inArray(["1","2"],true);
               $Validate->addColumn('province','省')->required()->lengthMin(2);
               $Validate->addColumn('city','市')->required()->lengthMin(2);
               $Validate->addColumn('area','区')->required()->lengthMin(2);
//               $Validate->addColumn('postcode','邮编')->required()->length(6);
               $Validate->addColumn('detail','详细地址')->required()->lengthMin(4);
//               $Validate->addColumn('distribution_type','配送日')->required()->inArray(["0","1","2"],true);
//               $Validate->addColumn('distribution_time','配送时段')->required()->lengthMin(2);
               $Validate->addColumn('state','状态')->required()->inArray(["0","1","2"],true);
               break;
           }

           //编辑资料
           case '/Api/V1/User/editInfo':{

               $Validate->addColumn('sex','性别')->required()->inArray(["1","2"],true);
               $Validate->addColumn('surname','姓')->required()->lengthMin(1);
               $Validate->addColumn('name','名')->required()->lengthMin(1);
               $Validate->addColumn('province','省')->required()->lengthMin(2);
               $Validate->addColumn('city','市')->required()->lengthMin(2);
               $Validate->addColumn('area','区')->required()->lengthMin(2);
               $Validate->addColumn('birthday','生日')->required()->lengthMin(6);
               break;
           }

       }
       return $Validate;

   }



    /**
     * 后台参数验证规则
     * @param $action
     * @return Validate
     * @author 品花
     * @date 2019/11/23 0023 下午 2:22
     */
    public static function adminValidateRule($action,$param)
    {

        $Validate = new Validate();
//        var_dump('$action'.$action);
        switch ($action) {
            //登录
            case '/Admin/Login/login':

                $Validate->addColumn('username', '账户')->required()->lengthMax(15);
                $Validate->addColumn('password', '密码')->required()->betweenLen(6, 12);
                break;
            case '/Admin/role/create':

                $Validate->addColumn('name', '角色名')->required()->lengthMax(20);
                $Validate->addColumn('authority_ids', '权限ID')->required()->lengthMax(255);
                break;
            case '/Admin/role/edit':
                 $Validate->addColumn('id', 'ID')->required()->lengthMax(15);
                 $Validate->addColumn('name', '角色名')->required()->lengthMax(20);
                 $Validate->addColumn('authority_ids', '权限ID')->required()->lengthMax(255);
                 break;
            case '/Admin/Authority/create':

                $Validate->addColumn('name', '权限名')->required()->lengthMax(15);
                $Validate->addColumn('client_route', '客户端路由')->required()->lengthMax(50);
                $Validate->addColumn('route', '路由')->required()->lengthMax(50);
                $Validate->addColumn('pid', '上级ID')->required()->integer();
                $Validate->addColumn('state', '状态')->required()->inArray([0,1]);

                break;
            case '/Admin/Authority/edit':
                $Validate->addColumn('id', 'ID')->required()->lengthMax(15);
                $Validate->addColumn('name', '权限名')->required()->lengthMax(15);
                $Validate->addColumn('client_route', '客户端路由')->required()->lengthMax(50);
                $Validate->addColumn('route', '路由')->required()->lengthMax(50);
                $Validate->addColumn('pid', '上级ID')->required()->integer();
                $Validate->addColumn('state', '状态')->required()->inArray([0,1]);

                break;
            case '/Admin/Manager/create':

                $Validate->addColumn('username', '用户名')->required()->lengthMax(15);
                $Validate->addColumn('password', '密码')->required()->lengthMax(20);
                $Validate->addColumn('phone', '手机号')->required()->length(11);
                $Validate->addColumn('nick', '昵称')->required()->lengthMax(16);
                $Validate->addColumn('wechat', '微信')->required()->lengthMax(32);
                $Validate->addColumn('qq', 'QQ')->required()->lengthMax(12);
                $Validate->addColumn('email', '邮箱')->required()->lengthMax(30);
                $Validate->addColumn('role_id', '角色ID')->required()->integer();
                $Validate->addColumn('state', '状态')->required()->inArray([0,1]);

                break;
            case '/Admin/Manager/edit':
                $Validate->addColumn('id', 'ID')->required()->lengthMax(15);
                $Validate->addColumn('password', '密码')->lengthMax(20);
                $Validate->addColumn('state', '状态')->inArray([0,1]);

                break;
            case '/Admin/Manager/editInfo':

                $Validate->addColumn('password', '密码')->lengthMax(20);

                break;
            case '/Admin/Config/edit':
                $Validate->addColumn('host', '系统域名')->required()->betweenLen(1,255);
                $Validate->addColumn('service_url', '客服聊天网址')->required()->lengthMin(1);
                break;


            case '/Admin/User/index':
                $Validate->addColumn('mobile', '手机号')->lengthMax(15);
                $Validate->addColumn('agent_status', '用户类型')->integer();
                $Validate->addColumn('state', '状态')->integer();
                break;
            case '/Admin/User/edit':
                $Validate->addColumn('id', 'ID')->required()->integer();
                break;

            case '/Admin/Version/create':
                $Validate->addColumn('version_str', '版本号')->required()->betweenLen(5,20);
                $Validate->addColumn('device_type', '设备类型')->required()->inArray(['1','2',true]);
                $Validate->addColumn('is_force_update', '是否强制更新')->required()->inArray(['0','1',true]);
                $Validate->addColumn('content', '更新说明')->required()->betweenLen(1,255);
                $Validate->addColumn('download_url', '下载地址')->required()->betweenLen(5,255);
                $Validate->addColumn('state', '状态')->required()->inArray(['1','2',true]);

                break;
            case '/Admin/Version/edit':
                $Validate->addColumn('id', 'ID')->required()->integer();
                $Validate->addColumn('version_str', '版本号')->required()->betweenLen(5,20);
                $Validate->addColumn('device_type', '设备类型')->required()->inArray(['1','2',true]);
                $Validate->addColumn('is_force_update', '是否强制更新')->required()->inArray(['0','1',true]);
                $Validate->addColumn('content', '更新说明')->required()->betweenLen(1,255);
                $Validate->addColumn('download_url', '下载地址')->required()->betweenLen(5,255);
                $Validate->addColumn('state', '状态')->required()->inArray(['1','2',true]);
                break;


            case '/Admin/Notice/create':
                $Validate->addColumn('content', '公告内容')->required()->lengthMin(10);
                $Validate->addColumn('state', '状态')->required()->inArray(["0","1"],true);
                break;
            case '/Admin/Notice/edit':
                $Validate->addColumn('id', 'ID')->required()->integer();
                $Validate->addColumn('content', '公告内容')->required()->lengthMin(10);
                $Validate->addColumn('state', '状态')->required()->inArray(["0","1"],true);
                break;


            case '/Admin/Products/create':
                $Validate->addColumn('title', '产品名')->required()->lengthMin(4);
                $Validate->addColumn('content', '产品详情')->required()->lengthMin(1);
                $Validate->addColumn('price', '单价')->required()->integer();
                $Validate->addColumn('weight', '重量')->required()->integer();
                $Validate->addColumn('original_price', '原价')->required()->decimal();
                $Validate->addColumn('img', '产品图')->required()->lengthMax(255);
                $Validate->addColumn('order_', '排序值')->required()->integer();
                $Validate->addColumn('stock', '库存')->required()->integer();
                $Validate->addColumn('state', '状态')->required()->inArray(['0','1',true]);

                break;
            case '/Admin/Products/edit':
                $Validate->addColumn('id', 'ID')->required()->integer();
                $Validate->addColumn('title', '产品名')->required()->lengthMin(4);
                $Validate->addColumn('content', '产品详情')->required()->lengthMin(1);
                $Validate->addColumn('price', '单价')->required()->integer();
                $Validate->addColumn('weight', '重量')->required()->integer();
                $Validate->addColumn('original_price', '原价')->required()->decimal();
                $Validate->addColumn('img', '产品图')->required()->lengthMax(255);
                $Validate->addColumn('order_', '排序值')->required()->integer();
                $Validate->addColumn('stock', '库存')->required()->integer();
                $Validate->addColumn('state', '状态')->required()->inArray(['0','1',true]);
                break;

            case '/Admin/Article/create':
                $Validate->addColumn('title', '标题')->required()->lengthMin(4);
                $Validate->addColumn('type_', '类型')->required()->inArray(['1','2',true]);
                $Validate->addColumn('sub_title', '副标题')->required()->lengthMin(1);
                $Validate->addColumn('img', '封面图')->required()->lengthMin(1);
                $Validate->addColumn('state', '状态')->required()->inArray(['0','1',true]);

                break;

            case '/Admin/Article/edit':

                $Validate->addColumn('id', 'ID')->required()->integer();
                $Validate->addColumn('title', '标题')->required()->lengthMin(4);
                $Validate->addColumn('type_', '类型')->required()->inArray(['1','2',true]);
//                $Validate->addColumn('content', '正文')->required()->lengthMin(1);
                $Validate->addColumn('sub_title', '副标题')->required()->lengthMin(1);
                $Validate->addColumn('img', '封面图')->required()->lengthMin(1);
                $Validate->addColumn('state', '状态')->required()->inArray(['0','1',true]);

                break;

            case '/Admin/Order/ship':
                $Validate->addColumn('order_id', '订单ID')->required()->integer();
                $Validate->addColumn('exp_name', '快递公司名')->required()->lengthMin(2);
                $Validate->addColumn('exp_no', '快递运单号')->required()->lengthMin(6);
                break;
        }

        return $Validate;
    }



}